package com.nas.crocus.controller;

import java.util.ArrayList;
import java.util.Collection;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.nas.crocus.dto.ItemDto;
import com.nas.crocus.service.PersonaService;


@Controller
@RequestMapping(value = "/page/persona")
public class PersonaPageController {
    
    @Autowired
    private PersonaService personaService;
    
    @Resource(name="menu")
    private Collection<ItemDto> menu;
    
    @RequestMapping(method = RequestMethod.GET)
    public String personas(Model model) {
        
        model.addAttribute("menu", menu);
        model.addAttribute("breadcrumb", getBreadcrumb());
        return "personaListado";
    }
    
    @RequestMapping(value = "/edicion/id/{id}", method = RequestMethod.GET)
    public String edicion(@PathVariable Long id, Model model) {
       
        ItemDto item = new ItemDto();
        //item.setDescripcion(evento.getNombre());
        item.setUrl("/app/page/persona/edicion/id/"+id);
        model.addAttribute("menu", menu);
        Collection <ItemDto> breadcrumb = getBreadcrumb();
        breadcrumb.add(item);
        model.addAttribute("breadcrumb", breadcrumb);
        model.addAttribute("personaId", id);
        return "personaFormulario";
    }
    
    @RequestMapping(value = "/alta", method = RequestMethod.GET)
    public String alta(Model model) {
        ItemDto item = new ItemDto();
        item.setDescripcion("Nueva persona");
        item.setUrl("/app/page/persona/alta");
        model.addAttribute("menu", menu);
        Collection <ItemDto> breadcrumb = getBreadcrumb();
        breadcrumb.add(item);
        model.addAttribute("breadcrumb", breadcrumb);
        
        return "personaFormulario";
    }
    private Collection<ItemDto> getBreadcrumb(){
        ArrayList<ItemDto> breadcum = new ArrayList<ItemDto>();
        ItemDto item = new ItemDto();
        item.setDescripcion("Personas");
        item.setUrl("/app/page/persona");
        breadcum.add(item);
        return breadcum;
    }
}
